from django.conf import settings
from django.http import HttpResponse
from django.views import View

from ali_http.dingding_request import InteractiveCardRequest
from ali_http.request import ChatRequest


class TestView(View):
    def get(self, request):
        utterance = request.GET.get('utterance')
        chat_request = ChatRequest()
        response = chat_request.get_answer(utterance)
        # response.messages
        return HttpResponse(response.messages)


class ChatView(View):
    def get_answer(self, request):
        utterance = request.GET.get('utterance', None)
        if utterance is None:
            return HttpResponse('error')
        chat_request = ChatRequest()
        response = chat_request.get_answer(utterance)
        response.messages
        return HttpResponse('ok')


class GroupView(View):
    def get(self, request):
        card_data_map = {
            'title': '测试',
            'type': '差旅费',
            'amount': '200',
            'reason': '没有'
        }

        r = InteractiveCardRequest('group')
        response = r.send({
            'card_data_map': card_data_map,
            'card_type': 'nomal',
            'card_template_id': settings.TEMPLATE_ID1
        })
        return HttpResponse('ok')
